--[[
处理收到的群消息

提前收到的声明数据为：
fromqq     消息的qq号码 number类型
fromgroup  消息的群号码 number类型
message    消息内容     string类型
id         消息id       number类型
fromAnonymous 消息是否匿名 bool类型


注意：拦截消息后请将变量handled置true，表示消息已被拦截，如：
handled = true

下面的代码为我当前接待喵逻辑使用的代码，可以重写也可以按自己需求进行更改
详细请参考readme
]]

-- 判断是否激活插件
if admin=="" then
    return true
end

-- 初始化发送消息函数
function sendMessage(m)
    if m == nil then
        return true
    end
    if cqSendGroupMessage(fromgroup, m) == -34 then
        -- 在群内被禁言了,在该群休眠
        apiXmlSet("","Shutup",tostring(fromgroup),"f")
    end
end

--记录语音配置
if apiXmlGet("record","recordconfig",tostring(fromgroup))=="t" then
    if message:find("%[CQ:record,file=")==1 and message:find("silk") then
        local total = apiXmlGet("record","record","total")
        if total=="" then
            total=0
        end
        total = tonumber(total)+1
        local n = message:gsub("%[CQ:record,file=",""):gsub("%]","")
        apiXmlSet("record","record",tostring(total),n)
        apiXmlSet("record","record","total",tostring(total))
    end
end

-- 开启群内聊天
if message:find("%[CQ:at,qq=" .. cqGetLoginQQ() .. "%]") and message:find("说话") and (fromqq==admin or "admin"==apiXmlGet('', 'adminList', tostring(fromqq)) or  'admin'==apiXmlGet(tostring(fromgroup), 'adminList', tostring(fromqq)) )then
    apiXmlSet("","Shutup",tostring(fromgroup),"t")
end

-- 默认设置群内休眠
if apiXmlGet("","Shutup",tostring(fromgroup))~="t" then
    return true
end

-- 监听转发
if apiXmlGet("","Monitorlog","Monitor") == "t" then
    local q = admin
    local cq = apiXmlGet("","Monitorlog","qq")
    if cq ~="" then
        q=cq
    end
    local dlist = apiXmlIdListGet("", "Monitor")
    local num = dlist[0]
    local list = dlist[1]
    for i = 0, num do
        if message:find(list[i]) then
            cqSendPrivateMessage(tonumber(q),"转发自群"..fromgroup.."\n发言QQ "..fromqq.."\n内容:\n"..message)
            break
        end
    end
end

-- 广告监听
local advert = apiXmlReplayGet("","advert",message)
if advert ~= "" then
    local cid = cqRepealMessage(id)
    if  cid == -42 or cid == -31 then
        sendMessage("管理员！"..cqCode_At(fromqq).." 在发广告！")
        return true
    end
    sendMessage(cqCode_At(fromqq).."发送违规信息，被我撤回了噢！快去处置他吧！")
    return true
end

-- 获取菜单列表
if message=="菜单" then
    return require("app.menu.group.groupfeatures")(fromgroup,fromqq,message,id,false)
end


if fromqq==admin or "admin"==apiXmlGet('', 'adminList', tostring(fromqq)) or  'admin'==apiXmlGet(tostring(fromgroup), 'adminList', tostring(fromqq)) then
    -- 获取设置列表
    if message=="设置" then
        return require("app.menu.group.groupmanage")(fromgroup,fromqq,message,id,false)
    end

    -- 执行设置功能
    if require("app.menu.group.groupmanage")(fromgroup,fromqq,message,id,true) then
        return true
    end
end
-- 执行菜单功能
if require("app.menu.group.groupfeatures")(fromgroup,fromqq,message,id,true) then
    return true
end


-- 消息回复
return require("app.menu.group.messagegroupSolve")(fromgroup,fromqq,message)